package com.ezandroid.alphago.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class AppPreference {

    private static final String OTHER_LOGIN_KEY = "OTHER_LOGIN";

    private static final String FORCE_SUPPORT_EWEIQI_KEY = "FORCE_SUPPORT_EWEIQI";

    private static final String SHOW_MANUAL_INFO_KEY = "SHOW_MANUAL_INFO";

    private static final String SHOW_NUMBER_WAY_KEY = "SHOW_NUMBER_WAY";

    private static final String SHOW_COORDINATE_KEY = "SHOW_COORDINATE";

    private static final String LAZI_SOUND_KEY = "LAZY_SOUND";

    private static final String LAZI_WAY_KEY = "LAZY_WAY";

    private static final String NO_WIFI_DOWN_COMICS_KEY = "NO_WIFI_DOWN_COMICS";

    private static final String NO_WIFI_DOWN_SGF_KEY = "NO_WIFI_DOWN_SGF";

    private static final String NO_WIFI_DOWN_BOOK_KEY = "NO_WIFI_DOWN_BOOK";

    private static final String NO_WIFI_DOWN_STORY_KEY = "NO_WIFI_DOWN_STORY";

    private static final String SAVE_MANUAL_PATH_KEY = "SAVE_MANUAL_PATH";

    private static final String AUTO_NEXT_INTERVAL_KEY = "AUTO_NEXT_INTERVAL";

    private static final String AUTO_REFRESH_INTERVAL_KEY = "AUTO_REFRESH_INTERVAL";

    private static final String AUTO_START_NEXT_KEY = "AUTO_START_NEXT";

    private static final String VOLUME_PLAY_KEY = "VOLUME_PLAY";

    private static final String CHESS_BOARD_COLOR_KEY = "CHESS_BOARD_COLOR";

    private static final String MANUAL_BACKGROUND_COLOR_KEY = "MANUAL_BACKGROUND_COLOR";

    private static final String CHESS_PIECE_STYLE_KEY = "CHESS_PIECE_STYLE";

    private static final String CHESS_PIECE_SHADOW_KEY = "CHESS_PIECE_SHADOW";

    private static final String LINE_WIDTH_KEY = "LINE_WIDTH";

    private static final String NUMBER_SIZE_KEY = "NUMBER_SIZE";

    private static final String CHESS_BOARD_STYLE_KEY = "CHESS_BOARD_STYLE";

    private static final String APP_TIPS_VERSION_KEY = "APP_TIPS_VERSION";

    private static final String POINTS_KEY = "POINTS";

    private static final String IS_FIRST_LAUNCH_KEY = "IS_FIRST_LAUNCH";

    private static final String IS_FIRST_MANUAL_KEY = "IS_FIRST_MANUAL";

    private static final String CLIENT_ID_KEY = "CLIENT_ID";

    private static final String KEYWORD_SEARCH_ENGINE_KEY = "KEYWORD_SEARCH_ENGINE_2.0";

    private static final String TOKEN_KEY = "TOKEN";

    private static final String IGS_USER_NAME_KEY = "IGS_USER_NAME";

    private static final String IGS_USER_PASSWORD_KEY = "IGS_USER_PASSWORD";

    private static final String USER_NAME_KEY = "USER_NAME";

    private static final String USER_PASSWORD_KEY = "USER_PASSWORD";

    private static final String FIRST_OPEN_COMICS_KEY = "FIRST_OPEN_COMICS";

    private static final String FIRST_OPEN_PDF_KEY = "FIRST_OPEN_PDF";

    private static final String FIRST_OPEN_STORY_KEY = "FIRST_STORY_PDF";

    private static final String PDF_READ_PAGE_KEY = "PDF_READ_PAGE";

    private static final String PDF_READ_NAME_KEY = "PDF_READ_NAME";

    private static final String UNZIP_SGF_VERSION_KEY = "UNZIP_SGF_VERSION";

    private static int sPieceShadow = -1;

    private static int sLineWidth = -1;

    private static int sBoardColor = -1;

    private static int sBoardStyle = -1;

    private static int sLaziWay = -1;

    private static int sManualColor = -1;

    private static int sPieceStyle = -1;

    private static int sShowNumber = -1;

    private static int sNumberSize = -1;

    public static void saveIsOtherLogin(Context context, boolean otherLogin) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(OTHER_LOGIN_KEY, otherLogin);
        editor.commit();
    }

    public static boolean isOtherLogin(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(OTHER_LOGIN_KEY, false);
    }

    public static void saveUnZipSGFVersion(Context context, int version) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(UNZIP_SGF_VERSION_KEY, version);
        editor.commit();
    }

    public static int getUnZipSGFVersion(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getInt(UNZIP_SGF_VERSION_KEY, 0);
    }

    public static void saveFirstOpenComics(Context context, boolean openComics) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(FIRST_OPEN_COMICS_KEY, openComics);
        editor.commit();
    }

    public static boolean getFirstOpenComics(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(FIRST_OPEN_COMICS_KEY, true);
    }

    public static void saveFirstOpenStory(Context context, boolean openStory) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(FIRST_OPEN_STORY_KEY, openStory);
        editor.commit();
    }

    public static boolean getFirstOpenStory(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(FIRST_OPEN_STORY_KEY, true);
    }

    public static void saveFirstOpenPDF(Context context, boolean openPDF) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(FIRST_OPEN_PDF_KEY, openPDF);
        editor.commit();
    }

    public static boolean getFirstOpenPDF(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(FIRST_OPEN_PDF_KEY, true);
    }

    public static String getIGSUserName(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(IGS_USER_NAME_KEY, "");
    }

    public static void saveIGSUserName(Context context, String userName) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(IGS_USER_NAME_KEY, userName);
        editor.commit();
    }

    public static String getIGSUserPassword(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(IGS_USER_PASSWORD_KEY, "");
    }

    public static void saveIGSUserPassword(Context context, String password) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(IGS_USER_PASSWORD_KEY, password);
        editor.commit();
    }

    public static String getUserName(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(USER_NAME_KEY, "");
    }

    public static void saveUserName(Context context, String userName) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(USER_NAME_KEY, userName);
        editor.commit();
    }

    public static String getUserPassword(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(USER_PASSWORD_KEY, "");
    }

    public static void saveUserPassword(Context context, String password) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(USER_PASSWORD_KEY, password);
        editor.commit();
    }

    public static String getToken(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(TOKEN_KEY, "");
    }

    public static void saveToken(Context context, String token) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(TOKEN_KEY, token);
        editor.commit();
    }

    public static String getClientId(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(CLIENT_ID_KEY, "");
    }

    public static void saveClientId(Context context, String clientId) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(CLIENT_ID_KEY, clientId);
        editor.commit();
    }

    public static void saveShowManualInfo(Context context, boolean showManualInfo) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(SHOW_MANUAL_INFO_KEY, showManualInfo);
        editor.commit();
    }

    public static boolean getShowManualInfo(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(SHOW_MANUAL_INFO_KEY, true);
    }

    public static void saveSupportEweiqi(Context context, boolean supportEweiqi) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(FORCE_SUPPORT_EWEIQI_KEY, supportEweiqi);
        editor.commit();
    }

    public static boolean getSupportEweiqi(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(FORCE_SUPPORT_EWEIQI_KEY, false);
    }

    public static void saveIsFirstLaunch(Context context, boolean isFirstLaunch) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(IS_FIRST_LAUNCH_KEY, isFirstLaunch);
        editor.apply(); // 异步保存
    }

    public static boolean getIsFirstLaunch(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(IS_FIRST_LAUNCH_KEY, true);
    }

    public static void saveIsFirstManual(Context context, boolean isFirstManual) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(IS_FIRST_MANUAL_KEY, isFirstManual);
        editor.commit();
    }

    public static boolean getIsFirstManual(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(IS_FIRST_MANUAL_KEY, true);
    }

    public static void saveAutoStartNext(Context context, boolean start) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(AUTO_START_NEXT_KEY, start);
        editor.commit();
    }

    public static boolean getAutoStartNext(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(AUTO_START_NEXT_KEY, false);
    }

    public static void saveVolumePlay(Context context, boolean play) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(VOLUME_PLAY_KEY, play);
        editor.commit();
    }

    public static boolean getVolumePlay(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(VOLUME_PLAY_KEY, false);
    }

    public static void savePoints(Context context, long points) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putLong(POINTS_KEY, points);
        editor.commit();
    }

    public static long getPoints(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getLong(POINTS_KEY, 0);
    }

    public static void saveKeywordSearchEngine(Context context, int engine) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(KEYWORD_SEARCH_ENGINE_KEY, engine);
        editor.commit();
    }

    public static int getKeywordSearchEngine(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getInt(KEYWORD_SEARCH_ENGINE_KEY,
                AppConstants.DEFAULT_KEYWORD_SEARCH_ENGINE);
    }

    public static void saveAppTipsVersion(Context context, int tipsVersion) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(APP_TIPS_VERSION_KEY, tipsVersion);
        editor.commit();
    }

    public static int getAppTipsVersion(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getInt(APP_TIPS_VERSION_KEY, 0);
    }

    public static void savePDFReadPage(Context context, int page) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(PDF_READ_PAGE_KEY, page);
        editor.commit();
    }

    public static int getPDFReadPage(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getInt(PDF_READ_PAGE_KEY, 0);
    }

    public static void savePDFReadName(Context context, String name) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(PDF_READ_NAME_KEY, name);
        editor.commit();
    }

    public static String getPDFReadName(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(PDF_READ_NAME_KEY, "");
    }

    public static void saveNumberSize(Context context, int size) {
        sNumberSize = size;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(NUMBER_SIZE_KEY, size);
        editor.commit();
    }

    public static int getNumberSize(Context context) {
        if (sNumberSize == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sNumberSize = preferences.getInt(NUMBER_SIZE_KEY, AppConstants.DEFAULT_NUMBER_SIZE);
        }
        return sNumberSize;
    }

    public static void saveLineWidth(Context context, int width) {
        sLineWidth = width;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(LINE_WIDTH_KEY, width);
        editor.commit();
    }

    public static int getLineWidth(Context context) {
        if (sLineWidth == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sLineWidth = preferences.getInt(LINE_WIDTH_KEY, AppConstants.DEFAULT_PIECE_SHADOW);
        }
        return sLineWidth;
    }

    public static void saveChessPieceShadow(Context context, int shadow) {
        sPieceShadow = shadow;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(CHESS_PIECE_SHADOW_KEY, shadow);
        editor.commit();
    }

    public static int getChessPieceShadow(Context context) {
        if (sPieceShadow == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sPieceShadow = preferences.getInt(CHESS_PIECE_SHADOW_KEY,
                    AppConstants.DEFAULT_PIECE_SHADOW);
        }
        return sPieceShadow;
    }

    public static void saveChessPieceStyle(Context context, int style) {
        sPieceStyle = style;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(CHESS_PIECE_STYLE_KEY, style);
        editor.commit();
    }

    public static int getChessPieceStyle(Context context) {
        if (sPieceStyle == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sPieceStyle = preferences.getInt(CHESS_PIECE_STYLE_KEY,
                    AppConstants.DEFAULT_PIECE_STYLE);
        }
        return sPieceStyle;
    }

    public static void saveLaziWay(Context context, int style) {
        sLaziWay = style;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(LAZI_WAY_KEY, style);
        editor.commit();
    }

    public static int getLaziWay(Context context) {
        if (sLaziWay == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sLaziWay = preferences.getInt(LAZI_WAY_KEY, AppConstants.DEFAULT_LAZI_WAY);
        }
        return sLaziWay;
    }

    public static void saveSavePath(Context context, String path) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(SAVE_MANUAL_PATH_KEY, path);
        editor.commit();
    }

    public static String getSavePath(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(SAVE_MANUAL_PATH_KEY, AppConstants.DEFAULT_SAVE_MANUAL_PATH);
    }

    public static void saveChessBoardStyle(Context context, int style) {
        sBoardStyle = style;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(CHESS_BOARD_STYLE_KEY, style);
        editor.commit();
    }

    public static int getChessBoardStyle(Context context) {
        if (sBoardStyle == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sBoardStyle = preferences.getInt(CHESS_BOARD_STYLE_KEY,
                    AppConstants.DEFAULT_BOARD_STYLE);
        }
        return sBoardStyle;
    }

    /**
     * 设置棋盘颜色
     *
     * @param context
     * @param color
     */
    public static void saveChessBoardColor(Context context, int color) {
        sBoardColor = color;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(CHESS_BOARD_COLOR_KEY, color);
        editor.commit();
    }

    /**
     * 获取棋盘颜色
     *
     * @param context
     * @return
     */
    public static int getChessBoardColor(Context context) {
        if (sBoardColor == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sBoardColor = preferences.getInt(CHESS_BOARD_COLOR_KEY,
                    AppConstants.DEFAULT_BOARD_COLOR);
        }
        return sBoardColor;
    }

    /**
     * 设置打谱背景颜色
     *
     * @param context
     * @param color
     */
    public static void saveManualBackgroundColor(Context context, int color) {
        sManualColor = color;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(MANUAL_BACKGROUND_COLOR_KEY, color);
        editor.commit();
    }

    /**
     * 获取打谱背景颜色
     *
     * @param context
     * @return
     */
    public static int getManualBackgroundColor(Context context) {
        if (sManualColor == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sManualColor = preferences.getInt(MANUAL_BACKGROUND_COLOR_KEY,
                    AppConstants.DEFAULT_MANUAL_COLOR);
        }
        return sManualColor;
    }

    public static void saveNoWifiDownBook(Context context, boolean noWifiDownBook) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(NO_WIFI_DOWN_BOOK_KEY, noWifiDownBook);
        editor.commit();
    }

    public static boolean getNoWifiDownBook(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(NO_WIFI_DOWN_BOOK_KEY, false);
    }

    public static void saveNoWifiDownComics(Context context, boolean noWifiDownComics) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(NO_WIFI_DOWN_COMICS_KEY, noWifiDownComics);
        editor.commit();
    }

    public static boolean getNoWifiDownComics(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(NO_WIFI_DOWN_COMICS_KEY, false);
    }

    public static void saveNoWifiDownStory(Context context, boolean noWifiDownBook) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(NO_WIFI_DOWN_STORY_KEY, noWifiDownBook);
        editor.commit();
    }

    public static boolean getNoWifiDownStory(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(NO_WIFI_DOWN_STORY_KEY, false);
    }

    public static void saveNoWifiDownSGF(Context context, boolean noWifiDownSGF) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(NO_WIFI_DOWN_SGF_KEY, noWifiDownSGF);
        editor.commit();
    }

    public static boolean getNoWifiDownSGF(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(NO_WIFI_DOWN_SGF_KEY, false);
    }

    public static void saveAutoNextInterval(Context context, String autoNextInterval) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putString(AUTO_NEXT_INTERVAL_KEY, autoNextInterval);
        editor.commit();
    }

    public static String getAutoNextInterval(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(AUTO_NEXT_INTERVAL_KEY, ""
                + AppConstants.DEFAULT_AUTO_NEXT_INTERVAL);
    }

    public static void saveAutoRefreshInterval(Context context, int autoRefreshInterval) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(AUTO_REFRESH_INTERVAL_KEY, autoRefreshInterval);
        editor.commit();
    }

    public static int getAutoRefreshInterval(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getInt(AUTO_REFRESH_INTERVAL_KEY,
                AppConstants.DEFAULT_AUTO_REFRESH_INTERVAL);
    }

    public static void saveShowNumber(Context context, int showNumber) {
        sShowNumber = showNumber;

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putInt(SHOW_NUMBER_WAY_KEY, showNumber);
        editor.commit();
    }

    public static int getShowNumber(Context context) {
        if (sShowNumber == -1) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            sShowNumber = preferences.getInt(SHOW_NUMBER_WAY_KEY, AppConstants.DEFAULT_SHOW_NUMBER);
        }
        return sShowNumber;
    }

    public static void saveShowCoordinate(Context context, boolean showCoordinate) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        Editor editor = preferences.edit();
        editor.putBoolean(SHOW_COORDINATE_KEY, showCoordinate);
        editor.commit();
    }

    public static boolean getShowCoordinate(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getBoolean(SHOW_COORDINATE_KEY, true);
    }
}
